/*
  包含多个接受组件通知触发mutation 调用间接更新转态的方法的对象
 */
import {ADD_TODO,DELETE_TODO,SELECT_ALL_TODOS,DELETE_COMPLETE_TODOS,REQ_TODOS} from "./mutation-types";
import storageUtil from "../util/storageUtil";
export default {
  // 添加todo
  addTodo({commit}, item) {
    console.log(arguments);
    // 添加数据到todos中
    commit(ADD_TODO, {item}); // 传一个对象过去，符合规范
  },
  // 删除todo
  deleteTodo({commit}, index) {
    commit(DELETE_TODO,{index})
  },
  // 更新状态
  selectAllTodos({commit}, value) {
    commit(SELECT_ALL_TODOS,{value})
  },
  // 清空所有已完成的todos
  deleteCompleteTodos({commit}) {
    commit(DELETE_COMPLETE_TODOS)
  },
  // 异步请求todos
  reqtodos({commit}) {
    setTimeout(() => {
      const todos = storageUtil.readTodos();
      commit(REQ_TODOS,{todos})
    }, 1000);
  }
}
